Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJhODllNzE0ZS00Yzg0LTRkODItYjIyMS01YjdiMmUwYWYzYjQiLCJpZCI6NDc2Niwic2NvcGVzIjpbImFzciIsImdjIl0sImlhdCI6MTU0MTU3ODM5Nn0.lmu860M6slhO6vd3kOEeoutjxpKe7D9aDAlkiZJIwno';


function createGoogleMapsByUrl(Cesium, options) {
    options = Cesium.defaultValue(options, {});

    var templateUrl = Cesium.defaultValue(options.url, 'http://mt1.google.cn/vt/lyrs=s&hl=zh-CN&x={x}&y={y}&z={z}');

    var trailingSlashRegex = /\/$/;
    var defaultCredit = new Cesium.Credit('Google Maps');

    var tilingScheme = new Cesium.WebMercatorTilingScheme({ellipsoid: options.ellipsoid});

    var tileWidth = 256;
    var tileHeight = 256;

    var minimumLevel = Cesium.defaultValue(options.minimumLevel, 0);
    var maximumLevel = Cesium.defaultValue(options.minimumLevel, 17);

    var rectangle = Cesium.defaultValue(options.rectangle, tilingScheme.rectangle);

    // Check the number of tiles at the minimum level.  If it's more than four,
    // throw an exception, because starting at the higher minimum
    // level will cause too many tiles to be downloaded and rendered.
    var swTile = tilingScheme.positionToTileXY(Cesium.Rectangle.southwest(rectangle), minimumLevel);
    var neTile = tilingScheme.positionToTileXY(Cesium.Rectangle.northeast(rectangle), minimumLevel);
    var tileCount = (Math.abs(neTile.x - swTile.x) + 1) * (Math.abs(neTile.y - swTile.y) + 1);
    //>>includeStart('debug', pragmas.debug);
    if (tileCount > 4) {
        throw new Cesium.DeveloperError('The rectangle and minimumLevel indicate that there are ' + tileCount + ' tiles at the minimum level. Imagery providers with more than four tiles at the minimum level are not supported.');
    }
    //>>includeEnd('debug');

    var credit = Cesium.defaultValue(options.credit, defaultCredit);
    if (typeof credit === 'string') {
        credit = new Cesium.Credit(credit);
    }

    return new Cesium.UrlTemplateImageryProvider({
        url: templateUrl,
        proxy: options.proxy,
        credit: credit,
        tilingScheme: tilingScheme,
        tileWidth: tileWidth,
        tileHeight: tileHeight,
        minimumLevel: minimumLevel,
        maximumLevel: maximumLevel,
        rectangle: rectangle
    });
}

/*var googlemap2 = createGoogleMapsByUrl(Cesium,{
    url:"http://mt1.google.cn/vt/lyrs=s&hl=zh-CN&x={x}&y={y}&z={z}"
});*/
var arcGisImages =new Cesium.ArcGisMapServerImageryProvider({
    url: 'http://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer'
})

var terrainProvider=new Cesium.CesiumTerrainProvider({
    url: Cesium.IonResource.fromAssetId(1)
});

var viewer = new Cesium.Viewer('cesiumContainer', {
    vrButton: true,
    infoBox: false,
    geocoder:true,
    selectionIndicator: false,
    terrainExaggeration: 1.0,
    creditContainer: 'bukejian', //ָ指定Cesium图标和文字输出div
    baseLayerPicker: false,
    navigationHelpButton: false,
    shadows: false,
    terrainShadows: true,
    fullscreenElement: 'cesiumContainer',
    //启动即加载影像
    imageryProvider: arcGisImages,
    terrainProvider:terrainProvider,
    shouldAnimate : true,
    timeline:false,
    animation:false
});

//天地图标注
var tdt = new Cesium.WebMapTileServiceImageryProvider({
    url:"http://t0.tianditu.com/cia_w/wmts?service=wmts&request=GetTile&version=1.0.0&LAYER=cia&tileMatrixSet=w&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}&style=default.jpg&tk=75a61e200cd9b492d50393ca071473f0",
    layer: "tdtlayer",
    style: "default",
    format: "image/jpeg",
    tileMatrixSetID: "GoogleMapsCompatible"
});
viewer.imageryLayers.addImageryProvider(tdt);

// //加载倾斜
// var tileset= viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
//     url :"http://localhost:8066/QXSY_lshdc/tileset.json",
//     cullWithChildrenBounds:false,
//     skipLevelOfDetail:true,
//     maximumMemoryUsage:1024,
//     oadSiblings:true
// }));
// tileset.readyPromise.then(function (tileset) {
//     viewer.zoomTo(tileset, new Cesium.HeadingPitchRange(0.0, -0.5, tileset.boundingSphere.radius * 2.0));
// });
// //导航
var options = {};
viewer.extend(Cesium.viewerCesiumNavigationMixin,options);
//屏蔽双击定位
//viewer.cesiumWidget.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
//3DTiles
viewer.extend(Cesium.viewerCesium3DTilesInspectorMixin);
var inspectorViewModel = viewer.cesium3DTilesInspector.viewModel;
inspectorViewModel.picking=false;//不可选择

var imageryLayers = viewer.imageryLayers;
var dataSources = viewer.dataSources;
var entities = viewer.entities;
var scene = viewer.scene;



//全局画笔定义
var G_DrawPan = 4;
var G_framecolor='#ffff00';
var G_fillcolor ='#ffff00';
var G_Alpha=.6;
// var G_framecolor =Cesium.Color.fromCssColorString('#ffff00');
// var G_fillcolor = Cesium.Color.fromCssColorString('#ffff00').withAlpha(0.6);
//隐藏3DTiles 设置框
$("div.cesium-viewer-cesium3DTilesInspectorContainer").css("display", "none");
// $("div.cesium-viewer-toolbar").css("display", "none");
$(".cesium-viewer-toolbar").css("top","10px");
$(".cesium-viewer-toolbar").css("right","100px");
$(".cesium-toolbar-button").css("display", "none");
$(".cesium-sceneModePicker-icon3D").css("display", "none");


// $(".cesium-viewer-toolbar").css("top","45px")
// $('.compass,.navigation-controls').css('display','block');
// $('.compass').css('top','80px');
// $('.navigation-controls').css('top','170px');

//打开阴影效果
//$('#ShadowState').css("background-color","#fff459");
//打开光照效果
viewer.scene.globe.enableLighting = false;
viewer.shadows =false;
// viewer.scene.globe.depthTestAgainstTerrain=true;
// $('#SetLighting').css("background-color", "#fff459");

//地理编码--可以自己写
Land3D.geocoder.init(viewer, {citycode: "",type: "geocoder"});
//绘图功能
var drawControl = new Land3D.Draw({viewer: viewer, terrain: !0,hasEdit: !0,
    onStopDrawing: function (t) {
        Land3d_Lib_onStopDrawing(t);
    }});
//初始化测量功能
var measureSurface = new Land3D.Measure({viewer: viewer, terrain: !1});

//初始位置
viewer.camera.setView( {
    destination  : Cesium.Cartesian3.fromDegrees(109.407908,24.226236,4000),
    orientation: {
        // heading : Cesium.Math.toRadians(90.0), // east, default value is 0.0 (north)
        pitch : Cesium.Math.toRadians(-20),    // default value (looking down)
        roll : 0.0                             // default value
    }
});

function ToCSView() {
    if(Cesium.defined(tileset))
        viewer.zoomTo(tileset, new Cesium.HeadingPitchRange(0.0, -0.5, tileset.boundingSphere.radius * 2.0));
};

